package com;

import ws.schild.jave.*;
import ws.schild.jave.encode.AudioAttributes;
import ws.schild.jave.encode.EncodingAttributes;
import ws.schild.jave.encode.VideoAttributes;
import ws.schild.jave.info.VideoSize;

import java.io.File;

public class VideoReencodeExample {
    public static void main(String[] args) throws Exception {
        // 输入视频文件
        File source = new File("C:\\Users\\Administrator\\Desktop\\e8d5b8fa77c387be5b4b79051c9612f0.mp4");
        // 输出视频文件
        File target = new File("C:\\Users\\Administrator\\Desktop\\222.mp4");

        // 视频转换的基本设置
        AudioAttributes audio = new AudioAttributes();
        audio.setCodec("aac"); // 设置音频编码器
        audio.setBitRate(128000); // 设置音频比特率
        audio.setChannels(2); // 设置音频通道数
        audio.setSamplingRate(44100); // 设置音频采样率

        VideoAttributes video = new VideoAttributes();
        video.setCodec("libx264"); // 设置视频编码器
        video.setBitRate(1600000); // 设置视频比特率
        video.setFrameRate(25); // 设置视频帧率
        video.setSize(new VideoSize(1280, 720)); // 设置视频尺寸

        // 转换设置
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setOutputFormat("mp4");
//        attrs.setFormat("mp4"); // 设置输出格式
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);

        // 执行转换
        Encoder encoder = new Encoder();
        encoder.encode(new MultimediaObject(source), target, attrs);
        
        System.out.println("视频重新编码完成。");
    }
}